package com.zretc.support.dao;

import com.zretc.support.entity.Log;
import com.zretc.support.entity.User;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.transaction.annotation.Transactional;

import java.io.Serializable;
import java.util.Date;

public interface LogDao extends JpaRepository<Log,Long>, JpaSpecificationExecutor<User>,
        CrudRepository<Log,Long>, Serializable {

    //分页查询+分页
    @Transactional
    @Query("select l from Log l inner join User u on l.user.userId = u.userId where l.user.userName like ?1% order by l.logId desc")
    Page<Log> findByLike(String username, Pageable pageable);

    //分页查询+分页(有时间限制)
    @Transactional
    @Query("select l from Log l inner join User u on l.user.userId = u.userId where l.user.userName like ?1% and l.logDate between ?2 and ?3 order by l.logId desc")
    Page<Log> findByDate(String username, Date startDate, Date endDate, Pageable pageable);

}
